﻿/*
 * 文件名称：
 * 程序员：huangsb
 * 创建时间：2008/05/10
 * 
 * 功能说明：图片配置
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Text;
using System.Drawing;
using Whir.Common;

public partial class Whir_System_Module_Config_PicConfig : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        if (!IsPostBack)
        {
            InstalledFontCollection ifc = new InstalledFontCollection();
            FontFamily[] ff = ifc.Families;
            foreach (FontFamily f in ff)
            {
                ListItem lt = new ListItem(f.Name.ToString(), f.Name.ToString());
                ddlFontList.Items.Add(lt);
            }

            BindData();
        }
    }

    private void BindData()
    {
        string xmlPath = Server.MapPath(Whir.Common.Settings.GetString("XmlPath") + "PicConfig.xml");
        //string xmlPath = Server.MapPath("~/" + Whir.Common.Settings.GetString("XmlPath") + "PicConfig.xml");
        Type type = typeof(Whir.Config.Model.PicConfig);
        Whir.Config.Model.PicConfig model = (Whir.Config.Model.PicConfig)Whir.Common.XmlHelper.DeserializeObject(xmlPath, type);         //反序列化
        chkIsEnable.Checked = Convert.ToBoolean(model.IsAutoMakeWatermark);
        rbShuiyinStyle1.Checked = model.WaterMarkStyle == "1" ? true : false;
        rbShuiyinStyle2.Checked = model.WaterMarkStyle == "1" ? false : true;
        if (rbShuiyinStyle1.Checked)
        {
            divfont.Visible = true;
            divPic.Visible = false;
        }
        else
        {
            divfont.Visible = false;
            divPic.Visible = true;
        }

        txtFontText.Text = model.WaterMarkFontText;
        ddlFontList.SelectedValue = model.WaterMarkFont;
        txtFontColor.Text = model.WaterMarkFontColor;
        txtFontSize.Text = model.WaterMarkFontSize;
        EzUpload1.Value = model.WaterMarkPic;
        EzUpload1.PreViewUrl = Settings.GetSystemPath() + "Whir_System/image/CommonImage/" + model.WaterMarkPic; //图片路径
        txtWidth.Text = model.WaterMarkPicWidth;
        txtHeight.Text = model.WaterMarkPicHeight;
        txtTransparent.Text = model.WaterMarkTransparent;

        if (model.WaterMarkWhere == "1") RadioButton1.Checked = true;
        else if (model.WaterMarkWhere == "2") RadioButton2.Checked = true;
        else if (model.WaterMarkWhere == "3") RadioButton3.Checked = true;
        else if (model.WaterMarkWhere == "4") RadioButton4.Checked = true;
        else if (model.WaterMarkWhere == "5") RadioButton5.Checked = true;
        else if (model.WaterMarkWhere == "6") RadioButton6.Checked = true;
        else if (model.WaterMarkWhere == "7") RadioButton7.Checked = true;
        else if (model.WaterMarkWhere == "8") RadioButton8.Checked = true;
        else if (model.WaterMarkWhere == "9") RadioButton9.Checked = true;
    }

    //修改
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Whir.Config.Model.PicConfig model = new Whir.Config.Model.PicConfig();
        model.IsAutoMakeWatermark = chkIsEnable.Checked.ToString();
        model.WaterMarkStyle = rbShuiyinStyle1.Checked ? "1" : "0";
        model.WaterMarkFontText = txtFontText.Text;
        model.WaterMarkFont = ddlFontList.SelectedItem.Value;
        model.WaterMarkFontColor = txtFontColor.Text.Trim();
        model.WaterMarkFontSize = txtFontSize.Text.Trim();

        if (EzUpload1.DefaultMode == Lib_ezModule_ezUpload.ModeState.Upload)
        {
            if (EzUpload1.inputFile.HasFile)
            {
                string path = Server.MapPath(Settings.GetSystemPath() + "Whir_System/image/CommonImage/");
                string destPath = System.IO.Path.Combine(path, EzUpload1.Value);
                EzUpload1.inputFile.MoveTo(destPath, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
            }
        }

        model.WaterMarkPic = EzUpload1.Value;
        model.WaterMarkPicWidth = txtWidth.Text.Trim();
        model.WaterMarkPicHeight = txtHeight.Text.Trim();
        model.WaterMarkTransparent = txtTransparent.Text.Trim();

        string temp = "";
        if (RadioButton1.Checked) temp = "1";
        else if (RadioButton2.Checked) temp = "2";
        else if (RadioButton3.Checked) temp = "3";
        else if (RadioButton4.Checked) temp = "4";
        else if (RadioButton5.Checked) temp = "5";
        else if (RadioButton6.Checked) temp = "6";
        else if (RadioButton7.Checked) temp = "7";
        else if (RadioButton8.Checked) temp = "8";
        else if (RadioButton9.Checked) temp = "9";

        model.WaterMarkWhere = temp;

        string xmlPath = Server.MapPath(Whir.Common.Settings.GetString("XmlPath") + "PicConfig.xml");
        //string xmlPath = Server.MapPath("~/" + Whir.Common.Settings.GetString("XmlPath") + "PicConfig.xml");
        Type type = typeof(Whir.Config.Model.PicConfig);
        Whir.Common.XmlHelper.SerializerObject(xmlPath, type, model);               //序列化

        this.OLAdd();    //操作日志
    }

    //操作日志
    protected void OLAdd()
    {
        Whir.Log.Model.Whir_OperateLog model = new Whir.Log.Model.Whir_OperateLog();
        model.title = "图片设置";
        model.operateType = 2;      //修改
        model.operateResult = true;
        model.operateDesc = "修改图片设置";

        Whir.Log.OperateLog.Add(model);
    }

    protected void rbShuiyinStyle1_CheckedChanged(object sender, EventArgs e)
    {
        divfont.Visible = true;
        divPic.Visible = false;
    }

    protected void rbShuiyinStyle2_CheckedChanged(object sender, EventArgs e)
    {
        divfont.Visible = false;
        divPic.Visible = true;
    }
}
